<?php
class Department_model extends CI_Model {
        
    public function __construct()
    {
        parent::__construct();
        $this->load->model('query');
        $this->config->load('iss_config');
    }
    
    public function get_department(){
         $sql = "SELECT dep_id, name FROM ".$this->config->item('schema').".department";
         return $this->query->department_query($sql);
    }
    public function get_department_by_id($id){
         
         $sql = "SELECT dep_id, name FROM ".$this->config->item('schema').".department where dep_id='".$id."'";
         return $this->query->department_query($sql);
    }
  
   public function update_department($data ){
       $this->session->set_flashdata('type', 'update');
        $this->session->set_flashdata('table', 'Derpartment');
        $sql = "UPDATE ".$this->config->item('schema').".Department
               SET 
                    name='".$data['name']."' "
                . "WHERE dep_id='".$data['dept_id']."'";
        return $this->query->update_dept_query($sql);
   }
    public function  store_department($data){
         $this->session->set_flashdata('type', 'add');
        $this->session->set_flashdata('table', 'Derpartment');
        $sql = "INSERT INTO ".$this->config->item('schema').".Department(dep_id,name) "
                . "values ('".$data['dept_id']."','".$data['name']."')" ;
         return $this->query->update_dept_query($sql);
    }
    public function delete_department($id){
        $this->session->set_flashdata('type', 'del');
        $this->session->set_flashdata('table', 'Derpartment');
        $sql = "DELETE FROM ".$this->config->item('schema').".Department WHERE dep_id='".$id."'";
        return $this->query->update_dept_query($sql);
    }

}